chore: add prettier auto-format hook for Claude Code#1037
chore: add prettier auto-format hook for Claude Code#1037dqnykamp merged 3 commits intoDoenet:mainfrom
Conversation
Adds .claude/settings.json with a PostToolUse hook that runs prettier on files after Write/Edit/MultiEdit/NotebookEdit operations. Ensures code is formatted automatically rather than relying on the agent to follow the "format with prettier before committing" instruction in CLAUDE.md (which was missed in PR Doenet#1036). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
There was a problem hiding this comment.
Pull request overview
Adds a Claude Code hook configuration to automatically run Prettier after file write/edit operations, aiming to keep agent-driven edits consistently formatted in this repo.
Changes:
- Add
.claude/settings.jsondefining aPostToolUsehook forWrite|Edit|MultiEdit|NotebookEdit. - Hook runs
npx --no-install prettier --write --ignore-unknownon the edited file path (when it appears to be under$PWD).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Redirect jq stderr to suppress noise on missing/erroring jq - Guard against empty file path with [ -n "$f" ] check - Use realpath to normalize paths before comparison, blocking path traversal via .. segments Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
.claude/settings.jsonwith aPostToolUsehook that runsprettier --write --ignore-unknownon files afterWrite/Edit/MultiEdit/NotebookEditoperations.AGENTS.md— which was missed in refactor(worker-javascript): extract Phase 1 helpers from Core.js #1036..prettierignore(auto-discovered by prettier) and only formats files inside the project directory.Test plan
/hooksonce (or restart Claude Code) so the new settings take effect..ts/.jsfile with formatting violations and confirming it gets auto-formatted on save..mdand other ignored paths are skipped (already covered by.prettierignore).🤖 Generated with Claude Code